﻿#include"CXinYueConfig.h"
#include"XClass.h"
#if !defined(XCONTAINEROBJECT_H)&& XContainerObject_ON
#define XCONTAINEROBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
#include<stdio.h>
#include<stdbool.h>
#include"XMemory.h"
#include"XTypes.h"
#include"XCompare.h"
//#define DEBUG_ON 1
//数据释放方法
typedef void (*XCDataDeinitMethod)(void* data);
//数据创建
typedef void (*XCDataCreatMethod)(void* data, const void* sData);
//数据拷贝
typedef  XCDataCreatMethod XCDataCopyMethod;
//数据移动
typedef XCDataCreatMethod XCDataMoveMethod;
//数据清除
typedef XCDataDeinitMethod XCDataClearMethod;

#define XCONTAINEROBJECT_VTABLE_SIZE   (XCLASS_VTABLE_GET_SIZE(XContainerObject))      //容器基类虚函数表大小
//XContainerObject虚函数表枚举
XCLASS_DEFINE_BEGING(XContainerObject)
XCLASS_DEFINE_ENUM(XContainerObject,IsEmpty) = XCLASS_VTABLE_GET_SIZE(XClass),
XCLASS_DEFINE_ENUM(XContainerObject,Size),
XCLASS_DEFINE_ENUM(XContainerObject,Capacity),
XCLASS_DEFINE_ENUM(XContainerObject,TypeSize),
XCLASS_DEFINE_ENUM(XContainerObject,Swap),
XCLASS_DEFINE_ENUM(XContainerObject,Clear),
XCLASS_DEFINE_END(XContainerObject)

//容器基类
typedef struct XContainerObject
{
	XClass m_class;
	XCDataCopyMethod m_dataCopyMethod;//数据拷贝方法
	XCDataMoveMethod m_dataMoveMethod;//数据移动方法
	XCDataDeinitMethod m_dataDeinitMethod;//数据释放方法
	XCompare m_compare;//比较大小方法
	void* m_data;//指向容器数据的指针
	size_t  m_capacity;//当前容器能容纳的最大元素数量
	size_t m_size;//当前容器内的元素个数
	size_t m_typeSize;//类型占用字节数
}XContainerObject;
//宏函数
#define XContainerValue(LPVal,type) (*(type*)LPVal)//派生类 读取数据 
#define XContainerDataPtr(Object) (((XContainerObject*)(Object))->m_data)//当前数据指针
#define XContainerData(Object,Type) (*(Type*)XContainerDataPtr(Object))//当前数据
#define XContainerCapacity(Object) (((XContainerObject*)(Object))->m_capacity)//当前容器能容纳的最大元素数量
#define XContainerSize(Object) (((XContainerObject*)(Object))->m_size)//当前容器内的元素个数
#define XContainerIsEmpty(Object) (XContainerSize(Object)==0)//当前容器是否时空的
#define XContainerTypeSize(Object) (((XContainerObject*)(Object))->m_typeSize)//类型占用字节数
#define XContainerDataCopyMethod(Object) (((XContainerObject*)(Object))->m_dataCopyMethod)//获取容器数据拷贝方法
#define XContainerSetDataCopyMethod(Object,method) (((XContainerObject*)(Object))->m_dataCopyMethod=method)//设置容器的数据拷贝方法
#define XContainerDataMoveMethod(Object) (((XContainerObject*)(Object))->m_dataMoveMethod)//获取容器数据移动方法
#define XContainerSetDataMoveMethod(Object,method) (((XContainerObject*)(Object))->m_dataMoveMethod=method)//设置容器的数据移动方法
#define XContainerDataDeinitMethod(Object) (((XContainerObject*)(Object))->m_dataDeinitMethod)//获取容器数据释放方法
#define XContainerSetDataDeinitMethod(Object,method) (((XContainerObject*)(Object))->m_dataDeinitMethod=method)//设置容器的数据释放方法
#define XContainerCompare(Object)		(((XContainerObject*)(Object))->m_compare)
#define XContainerSetCompare(Object,compare)    (((XContainerObject*)(Object))->m_compare=compare)
XVtable* XContainerObject_class_init();
void XContainerObject_init(XContainerObject* Object, size_t typeSize);
#define XContainerObject_copy_base		XClass_copy_base
#define XContainerObject_move_base		XClass_move_base
#define XContainerObject_deinit_base	XClass_deinit_base
#define XContainerObject_delete_base	XClass_delete_base
size_t XContainerObject_size_base(const XContainerObject* Object);
bool XContainerObject_isEmpty_base(const XContainerObject* Object);
size_t XContainerObject_capacity_base(const XContainerObject* Object);
size_t XContainerObject_typeSize_base(const XContainerObject* Object);
void XContainerObject_swap_base(XContainerObject* ObjectOne, XContainerObject* ObjectTwo);
void XContainerObject_clear_base(XContainerObject* Object);
#ifdef __cplusplus
}
#endif
#endif // !ContainerObject_h
